home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume10 / ptoc / part03 < prev    next >
Encoding:
Internet Message Format  |  1987-07-26  |  36.2 KB

  1. Path: uunet!rs
  2. From: rs@uunet.UU.NET (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v10i067:  Pascal to C translator, Part03/12
  5. Message-ID: <706@uunet.UU.NET>
  6. Date: 27 Jul 87 23:07:22 GMT
  7. Organization: UUNET Communications Services, Arlington, VA
  8. Lines: 1546
  9. Approved: rs@uunet.UU.NET
  10.  
  11. Submitted-by: Per Bergsten <mcvax!enea!chalmers!holtec!perb>
  12. Posting-number: Volume 10, Issue 67
  13. Archive-name: ptoc/Part03
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 3 (of 12)."
  22. # Contents:  ptc.c.1
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'ptc.c.1' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'ptc.c.1'\"
  26. else
  27. echo shar: Extracting \"'ptc.c.1'\" \(33774 characters\)
  28. sed "s/^X//" >'ptc.c.1' <<'END_OF_FILE'
  29. X/***************************************************************************/
  30. X/***************************************************************************/
  31. X/**                                      **/
  32. X/**    Copyright (C) 1987 by Per Bergsten, Gothenburg, Sweden          **/
  33. X/**                                      **/
  34. X/**    No part of this program, or parts derived from this program,      **/
  35. X/**    may be sold, hired or otherwise exploited without the author's      **/
  36. X/**    written consent.                          **/
  37. X/**                                      **/
  38. X/**    The program may be freely redistributed provided that:          **/
  39. X/**                                      **/
  40. X/**        1) the original program text, including this notice,      **/
  41. X/**           is reproduced unaltered,                  **/
  42. X/**        2) no charge (other than a nominal media cost) is      **/
  43. X/**           demanded for the copy.                  **/
  44. X/**                                      **/
  45. X/**    The program may be included in a package only on the condition      **/
  46. X/**    that the package as a whole is distributed at media cost.      **/
  47. X/**                                      **/
  48. X/***************************************************************************/
  49. X/***************************************************************************/
  50. X/**                                      **/
  51. X/**    The program is a Pascal-to-C translator.              **/
  52. X/**    It accepts a correct Pascal program and creates a C program      **/
  53. X/**    with the same behaviour. It is not a complete compiler in the      **/
  54. X/**    sense that it does NOT do complete typechecking or error-      **/
  55. X/**    reporting. Only a minimal typecheck is done so that the meaning      **/
  56. X/**    of each construct can be determined. Therefore, an incorrect      **/
  57. X/**    Pascal program can easily cause the translator to malfunction.      **/
  58. X/**                                      **/
  59. X/***************************************************************************/
  60. X/***************************************************************************/
  61. X/**                                      **/
  62. X/**    Things which are known to be dependent on the underlying cha-      **/
  63. X/**    racterset are marked with a comment containing the word    CHAR.      **/
  64. X/**    Things that are known to be dependent on the host operating      **/
  65. X/**    system are marked with a comment containing the word OS.      **/
  66. X/**    Things known to be dependent on the cpu and/or the target C-      **/
  67. X/**    implementation are marked with the word CPU.              **/
  68. X/**    Things dependent on the target C-library are marked with LIB.      **/
  69. X/**                                      **/
  70. X/**    The code generated by the translator assumes that there    is a      **/
  71. X/**    C-implementation with at least a reasonable <stdio> library      **/
  72. X/**    since all input/output is implemented in terms of C functions      **/
  73. X/**    like fprintf(), getc(), fopen(), rewind() etc.              **/
  74. X/**    If the source-program uses Pascal functions like sin(), sqrt()      **/
  75. X/**    etc, there must also exist such functions in the C-library.      **/
  76. X/**                                      **/
  77. X/***************************************************************************/
  78. X/***************************************************************************/
  79. X/*
  80. X**    Code derived from program ptc
  81. X*/
  82. Xextern void    exit();
  83. X/*
  84. X**    Definitions for i/o
  85. X*/
  86. X# include <stdio.h>
  87. Xtypedef struct {
  88. X    FILE    *fp;
  89. X    unsigned short    eoln:1,
  90. X            eof:1,
  91. X            out:1,
  92. X            init:1,
  93. X            :12;
  94. X    char    buf;
  95. X}     text;
  96. Xtext    input = { stdin, 0, 0 };
  97. Xtext    output = { stdout, 0, 0 };
  98. X# define Fread(x, f) fread((char *)&x, sizeof(x), 1, f)
  99. X# define Get(f) Fread((f).buf, (f).fp)
  100. X# define Getx(f) (f).init = 1, (f).eoln = (((f).buf = fgetc((f).fp)) == '\n') ? (((f).buf = ' '), 1) : 0
  101. X# define Getchr(f) (f).buf, Getx(f)
  102. Xstatic FILE    *Tmpfil;
  103. Xstatic long    Tmplng;
  104. Xstatic double    Tmpdbl;
  105. X# define Fscan(f) (f).init ? ungetc((f).buf, (f).fp) : 0, Tmpfil = (f).fp
  106. X# define Scan(p, a) Scanck(fscanf(Tmpfil, p, a))
  107. Xvoid    Scanck();
  108. X# define Eoln(f) ((f).eoln ? true : false)
  109. X# define Eof(f) ((((f).init == 0) ? (Get(f)) : 0, ((f).eof ? 1 : feof((f).fp))) ? true : false)
  110. X# define Fwrite(x, f) fwrite((char *)&x, sizeof(x), 1, f)
  111. X# define Put(f) Fwrite((f).buf, (f).fp)
  112. X# define Putx(f) (f).eoln = ((f).buf == '\n'), (void)fputc((f).buf, (f).fp)
  113. X# define Putchr(c, f) (f).buf = (c), Putx(f)
  114. X# define Putl(f, v) (f).eoln = v
  115. X/*
  116. X**    Definitions for case-statements
  117. X**    and for non-local gotos
  118. X*/
  119. X# define Line __LINE__
  120. Xvoid    Caseerror();
  121. X# include <setjmp.h>
  122. Xstatic struct Jb { jmp_buf    jb; } J[1];
  123. X/*
  124. X**    Definitions for standard types
  125. X*/
  126. Xextern int strncmp();
  127. X# define Cmpstr(x, y) strncmp((x), (y), sizeof(x))
  128. Xtypedef char    boolean;
  129. X# define false (boolean)0
  130. X# define true (boolean)1
  131. Xextern char    *Bools[];
  132. Xtypedef int    integer;
  133. X# define maxint    2147483647
  134. Xextern void abort();
  135. X/*
  136. X**    Definitions for pointers
  137. X*/
  138. X# ifndef Unionoffs
  139. X# define Unionoffs(p, m) (((long)(&(p)->m))-((long)(p)))
  140. X# endif
  141. X# define NIL 0
  142. Xextern char *malloc();
  143. X/*
  144. X**    Definitions for set-operations
  145. X*/
  146. X# define Claimset() (void)Currset(0, (setptr)0)
  147. X# define Newset() Currset(1, (setptr)0)
  148. X# define Saveset(s) Currset(2, s)
  149. X# define setbits 15
  150. Xtypedef unsigned short    setword;
  151. Xtypedef setword *    setptr;
  152. Xboolean    Member(), Le(), Ge(), Eq(), Ne();
  153. Xsetptr    Union(), Diff();
  154. Xsetptr    Insmem(), Mksubr();
  155. Xsetptr    Currset(), Inter();
  156. Xstatic setptr    Tmpset;
  157. Xextern setptr    Conset[];
  158. Xvoid    Setncpy();
  159. Xextern char *strncpy();
  160. X/*
  161. X**    Start of program definitions
  162. X*/
  163. Xstatic char    version[]    = "From: @(#)ptc.p    1.5  Date 87/05/01";
  164. Xstatic char    sccsid[]    = "@(#)ptc.c    1.2 Date 87/05/09";
  165. X# define keytablen 38
  166. X# define keywordlen 10
  167. Xstatic char    othersym[]    = "otherwise ";
  168. Xstatic char    externsym[]    = "external  ";
  169. Xstatic char    dummysym[]    = "          ";
  170. Xstatic char    wordtype[]    = "unsigned short";
  171. X# define C37_setbits 15
  172. Xstatic char    filebits[]    = "unsigned short";
  173. X# define filefill 12
  174. X# define maxsetrange 15
  175. X# define scalbase 0
  176. X# define maxprio 7
  177. X# define maxmachdefs 8
  178. X# define machdeflen 16
  179. X# define maxstrblk 1023
  180. X# define maxblkcnt 63
  181. X# define maxstrstor 65535
  182. X# define maxtoknlen 127
  183. X# define hashmax 64
  184. X# define null 0
  185. X# define minchar null
  186. X# define maxchar 127
  187. Xstatic char    tmpfilename[]    = "\"/tmp/ptc%d%c\", getpid(), ";
  188. X# define space ' '
  189. X# define tab1 '    '
  190. Xstatic char    tab2[]    = "        ";
  191. Xstatic char    tab3[]    = "            ";
  192. Xstatic char    tab4[]    = "                ";
  193. X# define bslash '\\'
  194. Xstatic char    nlchr[]    = "'\\n'";
  195. Xstatic char    ffchr[]    = "'\\f'";
  196. Xstatic char    nulchr[]    = "'\\0'";
  197. Xstatic char    spchr[]    = "' '";
  198. X# define quote '\''
  199. X# define cite '"'
  200. X# define xpnent 'e'
  201. X# define percent '%'
  202. X# define uscore '_'
  203. X# define badchr '?'
  204. X# define okchr quote
  205. X# define tabwidth 8
  206. X# define echo false
  207. X# define diffcomm false
  208. X# define lazyfor false
  209. X# define unionnew true
  210. Xstatic char    inttyp[]    = "int";
  211. Xstatic char    chartyp[]    = "char";
  212. Xstatic char    setwtyp[]    = "setword";
  213. Xstatic char    setptyp[]    = "setptr";
  214. Xstatic char    floattyp[]    = "float";
  215. Xstatic char    doubletyp[]    = "double";
  216. Xstatic char    dblcast[]    = "(double)";
  217. X# define realtyp doubletyp
  218. Xstatic char    voidtyp[]    = "void";
  219. Xstatic char    voidcast[]    = "(void)";
  220. X# define intlen 10
  221. X# define fixlen 20
  222. Xstatic char    C24_include[]    = "# include ";
  223. Xstatic char    C4_define[]    = "# define ";
  224. Xstatic char    ifdef[]    = "# ifdef ";
  225. Xstatic char    ifndef[]    = "# ifndef ";
  226. Xstatic char    elsif[]    = "# else";
  227. Xstatic char    endif[]    = "# endif";
  228. Xstatic char    C50_static[]    = "static ";
  229. Xstatic char    xtern[]    = "extern ";
  230. Xstatic char    typdef[]    = "typedef ";
  231. Xstatic char    registr[]    = "register ";
  232. X# define indstep 8
  233. Xtypedef unsigned char    hashtyp;
  234. Xtypedef unsigned short    strindx;
  235. Xtypedef unsigned short    strbidx;
  236. Xtypedef struct { char    A[maxstrblk + 1]; }    strblk;
  237. Xtypedef strblk *    strptr;
  238. Xtypedef unsigned char    strbcnt;
  239. Xtypedef struct S59 *    idptr;
  240. Xtypedef struct S59 {
  241. X    idptr    inext;
  242. X    unsigned char    inref;
  243. X    hashtyp    ihash;
  244. X    strindx    istr;
  245. X}    idnode;
  246. Xtypedef unsigned char    toknidx;
  247. Xtypedef struct { char    A[maxtoknlen - 1 + 1]; }    toknbuf;
  248. Xtypedef struct { char    A[keywordlen - 1 + 1]; }    keyword;
  249. Xtypedef enum { dabs, darctan, dargc, dargv,
  250. X    dboolean, dchar, dchr, dclose,
  251. X    dcos, ddispose, deof, deoln,
  252. X    dexit, dexp, dfalse, dflush,
  253. X    dget, dhalt, dinput, dinteger,
  254. X    dln, dmaxint, dmessage, dnew,
  255. X    dodd, dord, doutput, dpage,
  256. X    dpack, dpred, dput, dread,
  257. X    dreadln, dreal, dreset, drewrite,
  258. X    dround, dsin, dsqr, dsqrt,
  259. X    dsucc, dtext, dtrue, dtrunc,
  260. X    dtan, dwrite, dwriteln, dunpack,
  261. X    dzinit, dztring }     predefs;
  262. Xtypedef enum { sand, sarray, sbegin, scase,
  263. X    sconst, sdiv, sdo, sdownto,
  264. X    selse, send, sextern, sfile,
  265. X    sfor, sforward, sfunc, sgoto,
  266. X    sif, sinn, slabel, smod,
  267. X    snil, snot, sof, sor,
  268. X    sother, spacked, sproc, spgm,
  269. X    srecord, srepeat, sset, sthen,
  270. X    sto, stype, suntil, svar,
  271. X    swhile, swith, seof, sinteger,
  272. X    sreal, sstring, schar, sid,
  273. X    splus, sminus, smul, squot,
  274. X    sarrow, slpar, srpar, slbrack,
  275. X    srbrack, seq, sne, slt,
  276. X    sle, sgt, sge, scomma,
  277. X    scolon, ssemic, sassign, sdotdot,
  278. X    sdot }     symtyp;
  279. Xtypedef struct { setword    S[6]; }    symset;
  280. Xtypedef struct S180 {
  281. X    symtyp    st;
  282. X    union {
  283. X        struct  {
  284. X            idptr    vid;
  285. X        } V1;
  286. X        struct  {
  287. X            char    vchr;
  288. X        } V2;
  289. X        struct  {
  290. X            integer    vint;
  291. X        } V3;
  292. X        struct  {
  293. X            strindx    vflt;
  294. X        } V4;
  295. X        struct  {
  296. X            strindx    vstr;
  297. X        } V5;
  298. X    } U;
  299. X}    lexsym;
  300. Xtypedef enum { lpredef, lidentifier, lfield, lforward,
  301. X    lpointer, lstring, llabel, lforwlab,
  302. X    linteger, lreal, lcharacter }     ltypes;
  303. Xtypedef struct S60 *    declptr;
  304. Xtypedef struct S61 *    treeptr;
  305. Xtypedef struct S62 *    symptr;
  306. Xtypedef struct S62 {
  307. X    treeptr    lsymdecl;
  308. X    symptr    lnext;
  309. X    declptr    ldecl;
  310. X    ltypes    lt;
  311. X    union {
  312. X        struct  {
  313. X            idptr    lid;
  314. X            boolean    lused;
  315. X        } V6;
  316. X        struct  {
  317. X            strindx    lstr;
  318. X        } V7;
  319. X        struct  {
  320. X            strindx    lfloat;
  321. X        } V8;
  322. X        struct  {
  323. X            integer    lno;
  324. X            boolean    lgo;
  325. X        } V9;
  326. X        struct  {
  327. X            integer    linum;
  328. X        } V10;
  329. X        struct  {
  330. X            char    lchar;
  331. X        } V11;
  332. X    } U;
  333. X}    symnode;
  334. Xtypedef struct S60 {
  335. X    declptr    dprev;
  336. X    struct { symptr    A[hashmax + 1]; }    ddecl;
  337. X}    declnode;
  338. Xtypedef enum { npredef, npgm, nfunc, nproc,
  339. X    nlabel, nconst, ntype, nvar,
  340. X    nvalpar, nvarpar, nparproc, nparfunc,
  341. X    nsubrange, nvariant, nfield, nrecord,
  342. X    narray, nconfarr, nfileof, nsetof,
  343. X    nbegin, nptr, nscalar, nif,
  344. X    nwhile, nrepeat, nfor, ncase,
  345. X    nchoise, ngoto, nwith, nwithvar,
  346. X    nempty, nlabstmt, nassign, nformat,
  347. X    nin, neq, nne, nlt,
  348. X    nle, ngt, nge, nor,
  349. X    nplus, nminus, nand, nmul,
  350. X    ndiv, nmod, nquot, nnot,
  351. X    numinus, nuplus, nset, nrange,
  352. X    nindex, nselect, nderef, ncall,
  353. X    nid, nchar, ninteger, nreal,
  354. X    nstring, nnil, npush, npop,
  355. X    nbreak }     treetyp;
  356. Xtypedef enum { tnone, tboolean, tchar, tinteger,
  357. X    treal, tstring, tnil, tset,
  358. X    ttext, tpoly, terror }     pretyps;
  359. Xtypedef enum { anone, aregister, aextern, areference }     attributes;
  360. Xtypedef struct S61 {
  361. X    treeptr    tnext, ttype, tup;
  362. X    treetyp    tt;
  363. X    union {
  364. X        struct  {
  365. X            predefs    tdef;
  366. X            pretyps    tobtyp;
  367. X        } V12;
  368. X        struct  {
  369. X            treeptr    tsubid, tsubpar, tfuntyp, tsublab,
  370. X                tsubconst, tsubtype, tsubvar, tsubsub,
  371. X                tsubstmt;
  372. X            integer    tstat;
  373. X            declptr    tscope;
  374. X        } V13;
  375. X        struct  {
  376. X            treeptr    tidl, tbind;
  377. X            attributes    tattr;
  378. X        } V14;
  379. X        struct  {
  380. X            treeptr    tparid, tparparm, tpartyp;
  381. X        } V15;
  382. X        struct  {
  383. X            treeptr    tptrid;
  384. X            boolean    tptrflag;
  385. X        } V16;
  386. X        struct  {
  387. X            treeptr    tscalid;
  388. X        } V17;
  389. X        struct  {
  390. X            treeptr    tof;
  391. X        } V18;
  392. X        struct  {
  393. X            treeptr    tlo, thi;
  394. X        } V19;
  395. X        struct  {
  396. X            treeptr    tselct, tvrnt;
  397. X        } V20;
  398. X        struct  {
  399. X            treeptr    tflist, tvlist;
  400. X            idptr    tuid;
  401. X            declptr    trscope;
  402. X        } V21;
  403. X        struct  {
  404. X            treeptr    tcindx, tindtyp, tcelem;
  405. X            idptr    tcuid;
  406. X        } V22;
  407. X        struct  {
  408. X            treeptr    taindx, taelem;
  409. X        } V23;
  410. X        struct  {
  411. X            treeptr    tbegin;
  412. X        } V24;
  413. X        struct  {
  414. X            treeptr    tlabno, tstmt;
  415. X        } V25;
  416. X        struct  {
  417. X            treeptr    tlabel;
  418. X        } V26;
  419. X        struct  {
  420. X            treeptr    tlhs, trhs;
  421. X        } V27;
  422. X        struct  {
  423. X            treeptr    tglob, tloc, ttmp;
  424. X        } V28;
  425. X        struct  {
  426. X            treeptr    tbrkid, tbrkxp;
  427. X        } V29;
  428. X        struct  {
  429. X            treeptr    tcall, taparm;
  430. X        } V30;
  431. X        struct  {
  432. X            treeptr    tifxp, tthen, telse;
  433. X        } V31;
  434. X        struct  {
  435. X            treeptr    twhixp, twhistmt;
  436. X        } V32;
  437. X        struct  {
  438. X            treeptr    treptstmt, treptxp;
  439. X        } V33;
  440. X        struct  {
  441. X            treeptr    tforid, tfrom, tto, tforstmt;
  442. X            boolean    tincr;
  443. X        } V34;
  444. X        struct  {
  445. X            treeptr    tcasxp, tcaslst, tcasother;
  446. X        } V35;
  447. X        struct  {
  448. X            treeptr    tchocon, tchostmt;
  449. X        } V36;
  450. X        struct  {
  451. X            treeptr    twithvar, twithstmt;
  452. X        } V37;
  453. X        struct  {
  454. X            treeptr    texpw;
  455. X            declptr    tenv;
  456. X        } V38;
  457. X        struct  {
  458. X            treeptr    tvariable, toffset;
  459. X        } V39;
  460. X        struct  {
  461. X            treeptr    trecord, tfield;
  462. X        } V40;
  463. X        struct  {
  464. X            treeptr    texpl, texpr;
  465. X        } V41;
  466. X        struct  {
  467. X            treeptr    texps;
  468. X        } V42;
  469. X        struct  {
  470. X            symptr    tsym;
  471. X        } V43;
  472. X    } U;
  473. X}    treenode;
  474. Xtypedef enum { cabort, cbreak, ccontinue, cdefine,
  475. X    cdefault, cdouble, cedata, cenum,
  476. X    cetext, cextern, cfgetc, cfclose,
  477. X    cfflush, cfloat, cfloor, cfprintf,
  478. X    cfputc, cfread, cfscanf, cfwrite,
  479. X    cgetc, cgetpid, cint, cinclude,
  480. X    clong, clog, cmain, cmalloc,
  481. X    cprintf, cpower, cputc, cread,
  482. X    creturn, cregister, crewind, cscanf,
  483. X    csetbits, csetword, csetptr, cshort,
  484. X    csigned, csizeof, csprintf, cstdin,
  485. X    cstdout, cstderr, cstrncmp, cstrncpy,
  486. X    cstruct, cstatic, cswitch, ctypedef,
  487. X    cundef, cungetc, cunion, cunlink,
  488. X    cunsigned, cwrite }     cnames;
  489. Xtypedef enum { ebadsymbol, elongstring, elongtokn, erange,
  490. X    emanytokn, enotdeclid, emultdeclid, enotdecllab,
  491. X    emultdecllab, emuldeflab, ebadstring, enulchr,
  492. X    ebadchar, eeofcmnt, eeofstr, evarpar,
  493. X    enew, esetbase, esetsize, eoverflow,
  494. X    etree, etag, euprconf, easgnconf,
  495. X    ecmpconf, econfconf, evrntfile, evarfile,
  496. X    emanymachs, ebadmach }     errors;
  497. Xtypedef struct { char    A[machdeflen - 1 + 1]; }    machdefstr;
  498. Xtypedef struct { struct S206 {
  499. X    keyword    wrd;
  500. X    symtyp    sym;
  501. X}    A[keytablen + 1]; }    T63;
  502. Xtypedef struct { strptr    A[maxblkcnt + 1]; }    T64;
  503. Xtypedef struct { idptr    A[hashmax + 1]; }    T65;
  504. Xtypedef struct { treeptr    A[50]; }    T66;
  505. Xtypedef struct { symptr    A[50]; }    T67;
  506. Xtypedef struct { treeptr    A[11]; }    T68;
  507. Xtypedef struct { unsigned char    A[(int)(nnil) - (int)(nassign) + 1]; }    T69;
  508. Xtypedef struct { idptr    A[58]; }    T70;
  509. Xtypedef struct { struct S193 {
  510. X    integer    lolim, hilim;
  511. X    strindx    typstr;
  512. X}    A[maxmachdefs - 1 + 1]; }    T71;
  513. Xtypedef struct { char    A[15 + 1]; }    T72;
  514. Xtypedef struct { setword    S[2]; }    bitset;
  515. Xinteger    *G204_indnt;
  516. Xinteger    *G202_doarrow;
  517. Xboolean    *G200_donearr;
  518. Xboolean    *G198_dropset;
  519. Xboolean    *G196_setused;
  520. Xboolean    *G194_conflag;
  521. Xinteger    *G191_nelems;
  522. Xtreeptr    *G189_vp;
  523. Xtreeptr    *G187_tv;
  524. Xsymptr    *G185_iq;
  525. Xsymptr    *G183_ip;
  526. Xunsigned char    *G181_lastchr;
  527. Xtoknidx    *G178_i;
  528. Xtoknbuf    *G176_t;
  529. Xboolean    usemax, usejmps, usecase, usesets, useunion, usediff,
  530. X    usemksub, useintr, usesge, usesle, useseq, usesne,
  531. X    usememb, useins, usescpy, usecomp, usefopn, usescan,
  532. X    usegetl, usenilp, usebool;
  533. Xtreeptr    top;
  534. Xtreeptr    setlst;
  535. Xinteger    setcnt;
  536. Xlexsym    currsym;
  537. XT63    keytab;
  538. XT64    strstor;
  539. Xstrindx    strfree;
  540. Xstrbidx    strleft;
  541. XT65    idtab;
  542. Xdeclptr    symtab;
  543. Xinteger    statlvl, maxlevel;
  544. XT66    deftab;
  545. XT67    defnams;
  546. XT68    typnods;
  547. XT69    pprio, cprio;
  548. XT70    ctable;
  549. Xunsigned char    nmachdefs;
  550. XT71    machdefs;
  551. Xinteger    lineno, colno, lastcol, lastline;
  552. Xtoknbuf    lasttok;
  553. Xinteger    varno;
  554. XT72    hexdig;
  555. X
  556. X void
  557. Xprtmsg(m)
  558. X    errors    m;
  559. X{
  560. X    static char    user[]    = "Error: ";
  561. X    static char    restr[]    = "Implementation restriction: ";
  562. X    static char    inter[]    = "* Internal error * ";
  563. X# define xtoklen 64
  564. X    typedef struct { char    A[xtoklen - 1 + 1]; }    T73;
  565. X    toknidx    i;
  566. X    T73    xtok;
  567. X
  568. X    switch (m) {
  569. X      case ebadsymbol:
  570. X        (void)fprintf(stderr, "%sUnexpected symbol\n", user), Putl(output, 1);
  571. X        break ;
  572. X      case ebadchar:
  573. X        (void)fprintf(stderr, "%sBad character\n", user), Putl(output, 1);
  574. X        break ;
  575. X      case elongstring:
  576. X        (void)fprintf(stderr, "%sToo long string\n", restr), Putl(output, 1);
  577. X        break ;
  578. X      case ebadstring:
  579. X        (void)fprintf(stderr, "%sNewline in string or character\n", user), Putl(output, 1);
  580. X        break ;
  581. X      case eeofstr:
  582. X        (void)fprintf(stderr, "%sEnd of file in string or character\n", user), Putl(output, 1);
  583. X        break ;
  584. X      case eeofcmnt:
  585. X        (void)fprintf(stderr, "%sEnd of file in comment\n", user), Putl(output, 1);
  586. X        break ;
  587. X      case elongtokn:
  588. X        (void)fprintf(stderr, "%sToo long identfier\n", restr), Putl(output, 1);
  589. X        break ;
  590. X      case emanytokn:
  591. X        (void)fprintf(stderr, "%sToo many strings, identifiers or real numbers\n", restr), Putl(output, 1);
  592. X        break ;
  593. X      case enotdeclid:
  594. X        (void)fprintf(stderr, "%sIdentifier not declared\n", user), Putl(output, 1);
  595. X        break ;
  596. X      case emultdeclid:
  597. X        (void)fprintf(stderr, "%sIdentifier declared twice\n", user), Putl(output, 1);
  598. X        break ;
  599. X      case enotdecllab:
  600. X        (void)fprintf(stderr, "%sLabel not declared\n", user), Putl(output, 1);
  601. X        break ;
  602. X      case emultdecllab:
  603. X        (void)fprintf(stderr, "%sLabel declared twice\n", user), Putl(output, 1);
  604. X        break ;
  605. X      case emuldeflab:
  606. X        (void)fprintf(stderr, "%sLabel defined twice\n", user), Putl(output, 1);
  607. X        break ;
  608. X      case evarpar:
  609. X        (void)fprintf(stderr, "%sActual parameter not a variable\n", user), Putl(output, 1);
  610. X        break ;
  611. X      case enulchr:
  612. X        (void)fprintf(stderr, "%sCannot handle nul-character in strings\n", restr), Putl(output, 1);
  613. X        break ;
  614. X      case enew:
  615. X        (void)fprintf(stderr, "%sNew returned a nil-pointer\n", restr), Putl(output, 1);
  616. X        break ;
  617. X      case eoverflow:
  618. X        (void)fprintf(stderr, "%sToken buffer overflowed\n", restr), Putl(output, 1);
  619. X        break ;
  620. X      case esetbase:
  621. X        (void)fprintf(stderr, "%sCannot handle sets with base >> 0\n", restr), Putl(output, 1);
  622. X        break ;
  623. X      case esetsize:
  624. X        (void)fprintf(stderr, "%sCannot handle sets with very large range\n", restr), Putl(output, 1);
  625. X        break ;
  626. X      case etree:
  627. X        (void)fprintf(stderr, "%sBad tree structure\n", inter), Putl(output, 1);
  628. X        break ;
  629. X      case etag:
  630. X        (void)fprintf(stderr, "%sCannot find tag\n", inter), Putl(output, 1);
  631. X        break ;
  632. X      case evrntfile:
  633. X        (void)fprintf(stderr, "%sCannot initialize files in record variants\n", restr), Putl(output, 1);
  634. X        break ;
  635. X      case evarfile:
  636. X        (void)fprintf(stderr, "%sCannot handle files in structured variables\n", restr), Putl(output, 1);
  637. X        break ;
  638. X      case euprconf:
  639. X        (void)fprintf(stderr, "%sNo upper bound on conformant arrays\n", inter), Putl(output, 1);
  640. X        break ;
  641. X      case easgnconf:
  642. X        (void)fprintf(stderr, "%sCannot assign conformant arrays\n", inter), Putl(output, 1);
  643. X        break ;
  644. X      case ecmpconf:
  645. X        (void)fprintf(stderr, "%sCannot compare conformant arrays\n", inter), Putl(output, 1);
  646. X        break ;
  647. X      case econfconf:
  648. X        (void)fprintf(stderr, "%sCannot handle nested conformat arrays\n", restr), Putl(output, 1);
  649. X        break ;
  650. X      case erange:
  651. X        (void)fprintf(stderr, "%sCannot find C-type for integer-subrange\n", inter), Putl(output, 1);
  652. X        break ;
  653. X      case emanymachs:
  654. X        (void)fprintf(stderr, "%sToo many machine integer types\n", restr), Putl(output, 1);
  655. X        break ;
  656. X      case ebadmach:
  657. X        (void)fprintf(stderr, "%sBad name for machine integer type\n", inter), Putl(output, 1);
  658. X        break ;
  659. X      default:
  660. X        Caseerror(Line);
  661. X    }
  662. X    if (lastline != 0) {
  663. X        (void)fprintf(stderr, "Line %1d, col %1d:\n", lastline, lastcol), Putl(output, 1);
  664. X        if (Member((unsigned)(m), Conset[0])) {
  665. X            i = 1;
  666. X            while ((i < xtoklen) && (lasttok.A[i - 1] != null)) {
  667. X                xtok.A[i - 1] = lasttok.A[i - 1];
  668. X                i = i + 1;
  669. X            }
  670. X            while (i < xtoklen) {
  671. X                xtok.A[i - 1] = ' ';
  672. X                i = i + 1;
  673. X            }
  674. X            xtok.A[xtoklen - 1] = ' ';
  675. X            (void)fprintf(stderr, "Current symbol: %.64s\n", xtok.A), Putl(output, 1);
  676. X        }
  677. X    }
  678. X}
  679. X
  680. Xvoid fatal();
  681. X
  682. Xvoid error();
  683. X
  684. X char
  685. Xuppercase(c)
  686. X    char    c;
  687. X{
  688. X    register char    R75;
  689. X
  690. X    if ((c >= 'a') && (c <= 'z'))
  691. X        R75 = (unsigned)(c) + (unsigned)('A') - (unsigned)('a');
  692. X    else
  693. X        R75 = c;
  694. X    return R75;
  695. X}
  696. X
  697. X char
  698. Xlowercase(c)
  699. X    char    c;
  700. X{
  701. X    register char    R76;
  702. X
  703. X    if ((c >= 'A') && (c <= 'Z'))
  704. X        R76 = (unsigned)(c) - (unsigned)('A') + (unsigned)('a');
  705. X    else
  706. X        R76 = c;
  707. X    return R76;
  708. X}
  709. X
  710. X void
  711. Xgettokn(i, t)
  712. X    strindx    i;
  713. X    toknbuf    *t;
  714. X{
  715. X    char    c;
  716. X    toknidx    k;
  717. X    strbidx    j;
  718. X    strptr    p;
  719. X
  720. X    k = 1;
  721. X    p = strstor.A[i / (maxstrblk + 1)];
  722. X    j = i % (maxstrblk + 1);
  723. X    do {
  724. X        c = p->A[j];
  725. X        t->A[k - 1] = c;
  726. X        j = j + 1;
  727. X        k = k + 1;
  728. X        if (k == maxtoknlen) {
  729. X            c = null;
  730. X            t->A[maxtoknlen - 1] = null;
  731. X            prtmsg(eoverflow);
  732. X        }
  733. X    } while (!(c == null));
  734. X}
  735. X
  736. X void
  737. Xputtokn(i, t)
  738. X    strindx    i;
  739. X    toknbuf    *t;
  740. X{
  741. X    char    c;
  742. X    toknidx    k;
  743. X    strbidx    j;
  744. X    strptr    p;
  745. X
  746. X    k = 1;
  747. X    p = strstor.A[i / (maxstrblk + 1)];
  748. X    j = i % (maxstrblk + 1);
  749. X    do {
  750. X        c = t->A[k - 1];
  751. X        p->A[j] = c;
  752. X        k = k + 1;
  753. X        j = j + 1;
  754. X    } while (!(c == null));
  755. X}
  756. X
  757. X void
  758. Xwritetok(w)
  759. X    toknbuf    *w;
  760. X{
  761. X    toknidx    j;
  762. X
  763. X    j = 1;
  764. X    while (w->A[j - 1] != null) {
  765. X        Putchr(w->A[j - 1], output);
  766. X        j = j + 1;
  767. X    }
  768. X}
  769. X
  770. X void
  771. Xprinttok(i)
  772. X    strindx    i;
  773. X{
  774. X    toknbuf    w;
  775. X
  776. X    gettokn(i, &w);
  777. X    writetok(&w);
  778. X}
  779. X
  780. X void
  781. Xprintid(ip)
  782. X    idptr    ip;
  783. X{
  784. X    printtok(ip->istr);
  785. X}
  786. X
  787. X void
  788. Xprintchr(c)
  789. X    char    c;
  790. X{
  791. X    if ((c == quote) || (c == bslash))
  792. X        (void)fprintf(output.fp, "%c%c%c%c", quote, bslash, c, quote), Putl(output, 0);
  793. X    else
  794. X        (void)fprintf(output.fp, "%c%c%c", quote, c, quote), Putl(output, 0);
  795. X}
  796. X
  797. X void
  798. Xprintstr(i)
  799. X    strindx    i;
  800. X{
  801. X    toknidx    k;
  802. X    char    c;
  803. X    toknbuf    w;
  804. X
  805. X    gettokn(i, &w);
  806. X    Putchr(cite, output);
  807. X    k = 1;
  808. X    while (w.A[k - 1] != null) {
  809. X        c = w.A[k - 1];
  810. X        k = k + 1;
  811. X        if ((c == cite) || (c == bslash))
  812. X            Putchr(bslash, output);
  813. X        Putchr(c, output);
  814. X    }
  815. X    Putchr(cite, output);
  816. X}
  817. X
  818. X treeptr
  819. Xidup(ip)
  820. X    treeptr    ip;
  821. X{
  822. X    register treeptr    R77;
  823. X
  824. X    R77 = ip->U.V43.tsym->lsymdecl->tup;
  825. X    return R77;
  826. X}
  827. X
  828. X hashtyp
  829. Xhashtokn(id)
  830. X    toknbuf    *id;
  831. X{
  832. X    register hashtyp    R78;
  833. X    integer    h;
  834. X    toknidx    i;
  835. X
  836. X    i = 1;
  837. X    h = 0;
  838. X    while (id->A[i - 1] != null) {
  839. X        h = h + (unsigned)(id->A[i - 1]);
  840. X        i = i + 1;
  841. X    }
  842. X    R78 = h % hashmax;
  843. X    return R78;
  844. X}
  845. X
  846. X strindx
  847. Xsavestr(t)
  848. X    toknbuf    *t;
  849. X{
  850. X    register strindx    R79;
  851. X    toknidx    k;
  852. X    strindx    i;
  853. X    strbcnt    j;
  854. X
  855. X    k = 1;
  856. X    while (t->A[k - 1] != null)
  857. X        k = k + 1;
  858. X    if (k > strleft) {
  859. X        if (strstor.A[maxblkcnt] != (strblk *)NIL)
  860. X            error(emanytokn);
  861. X        j = (strfree + maxstrblk) / (maxstrblk + 1);
  862. X        strstor.A[j] = (strblk *)malloc((unsigned)(sizeof(*strstor.A[j])));
  863. X        if (strstor.A[j] == (strblk *)NIL)
  864. X            error(enew);
  865. X        strfree = j * (maxstrblk + 1);
  866. X        strleft = maxstrblk;
  867. X    }
  868. X    i = strfree;
  869. X    strfree = strfree + k;
  870. X    strleft = strleft - k;
  871. X    puttokn(i, &(*t));
  872. X    R79 = i;
  873. X    return R79;
  874. X}
  875. X
  876. X idptr
  877. Xsaveid(id)
  878. X    toknbuf    *id;
  879. X{
  880. X    register idptr    R80;
  881. X    toknidx    k;
  882. X    idptr    ip;
  883. X    hashtyp    h;
  884. X    toknbuf    t;
  885. X
  886. X    h = hashtokn(&(*id));
  887. X    ip = idtab.A[h];
  888. X    while (ip != (struct S59 *)NIL) {
  889. X        gettokn(ip->istr, &t);
  890. X        k = 1;
  891. X        while (id->A[k - 1] == t.A[k - 1])
  892. X            if (id->A[k - 1] == null)
  893. X                goto L999;
  894. X            else
  895. X                k = k + 1;
  896. X        ip = ip->inext;
  897. X    }
  898. X    ip = (struct S59 *)malloc((unsigned)(sizeof(*ip)));
  899. X    if (ip == (struct S59 *)NIL)
  900. X        error(enew);
  901. X    ip->inref = 0;
  902. X    ip->istr = savestr(&(*id));
  903. X    ip->ihash = h;
  904. X    ip->inext = idtab.A[h];
  905. X    idtab.A[h] = ip;
  906. XL999:
  907. X    R80 = ip;
  908. X    return R80;
  909. X}
  910. X
  911. X idptr
  912. Xmkconc(sep, p, q)
  913. X    char    sep;
  914. X    idptr    p, q;
  915. X{
  916. X    register idptr    R81;
  917. X    toknbuf    w, x;
  918. X    toknidx    i, j;
  919. X
  920. X    gettokn(q->istr, &x);
  921. X    j = 1;
  922. X    while (x.A[j - 1] != null)
  923. X        j = j + 1;
  924. X    w.A[1 - 1] = null;
  925. X    if (p != (struct S59 *)NIL)
  926. X        gettokn(p->istr, &w);
  927. X    i = 1;
  928. X    while (w.A[i - 1] != null)
  929. X        i = i + 1;
  930. X    if (i + j + 2 >= maxtoknlen)
  931. X        error(eoverflow);
  932. X    if (sep == '>') {
  933. X        w.A[i - 1] = '-';
  934. X        i = i + 1;
  935. X    }
  936. X    if (sep != space) {
  937. X        w.A[i - 1] = sep;
  938. X        i = i + 1;
  939. X    }
  940. X    j = 1;
  941. X    do {
  942. X        w.A[i - 1] = x.A[j - 1];
  943. X        i = i + 1;
  944. X        j = j + 1;
  945. X    } while (!(w.A[i - 1 - 1] == null));
  946. X    R81 = saveid(&w);
  947. X    return R81;
  948. X}
  949. X
  950. Xidptr mkuniqname();
  951. X
  952. X void
  953. Xdig(n)
  954. X    integer    n;
  955. X{
  956. X    if (n > 0) {
  957. X        dig(n / 10);
  958. X        if ((*G178_i) == maxtoknlen)
  959. X            error(eoverflow);
  960. X        (*G176_t).A[(*G178_i) - 1] = n % 10 + (unsigned)('0');
  961. X        (*G178_i) = (*G178_i) + 1;
  962. X    }
  963. X}
  964. X
  965. X idptr
  966. Xmkuniqname(t)
  967. X    toknbuf    *t;
  968. X{
  969. X    register idptr    R82;
  970. X    toknidx    i;
  971. X    toknbuf    *F177;
  972. X    toknidx    *F179;
  973. X
  974. X    F179 = G178_i;
  975. X    G178_i = &i;
  976. X    F177 = G176_t;
  977. X    G176_t = &(*t);
  978. X    (*G178_i) = 1;
  979. X    while ((*G176_t).A[(*G178_i) - 1] != null)
  980. X        (*G178_i) = (*G178_i) + 1;
  981. X    varno = varno + 1;
  982. X    dig(varno);
  983. X    (*G176_t).A[(*G178_i) - 1] = null;
  984. X    R82 = saveid(&(*G176_t));
  985. X    G176_t = F177;
  986. X    G178_i = F179;
  987. X    return R82;
  988. X}
  989. X
  990. X idptr
  991. Xmkvariable(c)
  992. X    char    c;
  993. X{
  994. X    register idptr    R83;
  995. X    toknbuf    t;
  996. X
  997. X    t.A[1 - 1] = c;
  998. X    t.A[2 - 1] = null;
  999. X    R83 = mkuniqname(&t);
  1000. X    return R83;
  1001. X}
  1002. X
  1003. X idptr
  1004. Xmkrename(c, ip)
  1005. X    char    c;
  1006. X    idptr    ip;
  1007. X{
  1008. X    register idptr    R84;
  1009. X
  1010. X    R84 = mkconc(uscore, mkvariable(c), ip);
  1011. X    return R84;
  1012. X}
  1013. X
  1014. X idptr
  1015. Xmkvrnt()
  1016. X{
  1017. X    register idptr    R85;
  1018. X    toknbuf    t;
  1019. X
  1020. X    t.A[1 - 1] = 'U';
  1021. X    t.A[2 - 1] = '.';
  1022. X    t.A[3 - 1] = 'V';
  1023. X    t.A[4 - 1] = null;
  1024. X    R85 = mkuniqname(&t);
  1025. X    return R85;
  1026. X}
  1027. X
  1028. X void
  1029. Xchecksymbol(ss)
  1030. X    symset    ss;
  1031. X{
  1032. X    if (!(Member((unsigned)(currsym.st), ss.S)))
  1033. X        error(ebadsymbol);
  1034. X}
  1035. X
  1036. Xvoid nextsymbol();
  1037. X
  1038. X char
  1039. Xnextchar()
  1040. X{
  1041. X    register char    R86;
  1042. X    char    c;
  1043. X
  1044. X    if (Eof(input))
  1045. X        c = null;
  1046. X    else {
  1047. X        colno = colno + 1;
  1048. X        if (Eoln(input)) {
  1049. X            lineno = lineno + 1;
  1050. X            colno = 0;
  1051. X        }
  1052. X        c = Getchr(input);
  1053. X        if (echo)
  1054. X            if (colno == 0)
  1055. X                Putchr('\n', output);
  1056. X            else
  1057. X                Putchr(c, output);
  1058. X        if (c == tab1)
  1059. X            colno = ((colno / tabwidth) + 1) * tabwidth;
  1060. X    }
  1061. X    if ((*G181_lastchr) > 0) {
  1062. X        lasttok.A[(*G181_lastchr) - 1] = c;
  1063. X        (*G181_lastchr) = (*G181_lastchr) + 1;
  1064. X    }
  1065. X    R86 = c;
  1066. X    return R86;
  1067. X}
  1068. X
  1069. X char
  1070. Xpeekchar()
  1071. X{
  1072. X    register char    R87;
  1073. X
  1074. X    if (Eof(input))
  1075. X        R87 = null;
  1076. X    else
  1077. X        R87 = input.buf;
  1078. X    return R87;
  1079. X}
  1080. X
  1081. Xvoid nexttoken();
  1082. X
  1083. X boolean
  1084. Xidchar(c)
  1085. X    char    c;
  1086. X{
  1087. X    register boolean    R88;
  1088. X
  1089. X    R88 = (boolean)((c >= 'a') && (c <= 'z') || (c >= '0') && (c <= '9') || (c >= 'A') && (c <= 'Z') || (c == uscore));
  1090. X    return R88;
  1091. X}
  1092. X
  1093. X boolean
  1094. Xnumchar(c)
  1095. X    char    c;
  1096. X{
  1097. X    register boolean    R89;
  1098. X
  1099. X    R89 = (boolean)((c >= '0') && (c <= '9'));
  1100. X    return R89;
  1101. X}
  1102. X
  1103. X integer
  1104. Xnumval(c)
  1105. X    char    c;
  1106. X{
  1107. X    register integer    R90;
  1108. X
  1109. X    R90 = (unsigned)(c) - (unsigned)('0');
  1110. X    return R90;
  1111. X}
  1112. X
  1113. X symtyp
  1114. Xkeywordcheck(w, l)
  1115. X    toknbuf    *w;
  1116. X    toknidx    l;
  1117. X{
  1118. X    register symtyp    R91;
  1119. X    register unsigned char    n;
  1120. X    unsigned char    i, j, k;
  1121. X    keyword    wrd;
  1122. X    symtyp    kwc;
  1123. X
  1124. X    if ((l > 1) && (l < keywordlen)) {
  1125. X        wrd = keytab.A[keytablen].wrd;
  1126. X        {
  1127. X            unsigned char    B44 = 1,
  1128. X                B45 = l;
  1129. X
  1130. X            if (B44 <= B45)
  1131. X                for (n = B44; ; n++) {
  1132. X                    wrd.A[n - 1] = w->A[n - 1];
  1133. X                    if (n == B45) break;
  1134. X                }
  1135. X        }
  1136. X        i = 0;
  1137. X        j = keytablen;
  1138. X        while (j > i) {
  1139. X            k = (i + j) / 2;
  1140. X            if (Cmpstr(keytab.A[k].wrd.A, wrd.A) >= 0)
  1141. X                j = k;
  1142. X            else
  1143. X                i = k + 1;
  1144. X        }
  1145. X        if (Cmpstr(keytab.A[j].wrd.A, wrd.A) == 0)
  1146. X            kwc = keytab.A[j].sym;
  1147. X        else
  1148. X            kwc = sid;
  1149. X    } else
  1150. X        kwc = sid;
  1151. X    R91 = kwc;
  1152. X    return R91;
  1153. X}
  1154. X
  1155. X void
  1156. Xnexttoken(realok)
  1157. X    boolean    realok;
  1158. X{
  1159. X    char    c;
  1160. X    integer    n;
  1161. X    boolean    ready;
  1162. X    toknidx    wl;
  1163. X    toknbuf    wb;
  1164. X
  1165. X    (*G181_lastchr) = 0;
  1166. X    do {
  1167. X        c = nextchar();
  1168. X        if (c == '{') {
  1169. X            do {
  1170. X                c = nextchar();
  1171. X                if (diffcomm)
  1172. X                    ready = (boolean)(c == '}');
  1173. X                else
  1174. X                    ready = (boolean)(((c == '*') && (peekchar() == ')')) || (c == '}'));
  1175. X            } while (!(ready || Eof(input)));
  1176. X            if (Eof(input) && !ready)
  1177. X                error(eeofcmnt);
  1178. X            if ((c == '*') && !Eof(input))
  1179. X                c = nextchar();
  1180. X            c = space;
  1181. X        } else
  1182. X            if ((c == '(') && (peekchar() == '*')) {
  1183. X                c = nextchar();
  1184. X                do {
  1185. X                    c = nextchar();
  1186. X                    if (diffcomm)
  1187. X                        ready = (boolean)((c == '*') && (peekchar() == ')'));
  1188. X                    else
  1189. X                        ready = (boolean)(((c == '*') && (peekchar() == ')')) || (c == '}'));
  1190. X                } while (!(ready || Eof(input)));
  1191. X                if (Eof(input) && !ready)
  1192. X                    error(eeofcmnt);
  1193. X                if ((c == '*') && !Eof(input))
  1194. X                    c = nextchar();
  1195. X                c = space;
  1196. X            }
  1197. X    } while (!((c != space) && (c != tab1)));
  1198. X    lasttok.A[1 - 1] = c;
  1199. X    (*G181_lastchr) = 2;
  1200. X    lastcol = colno;
  1201. X    lastline = lineno;
  1202. X    if (c < okchr)
  1203. X        c = badchr;
  1204. X    {
  1205. X        register struct S180 *W46 = &currsym;
  1206. X
  1207. X        if (Eof(input)) {
  1208. X            lasttok.A[1 - 1] = '*';
  1209. X            lasttok.A[2 - 1] = 'E';
  1210. X            lasttok.A[3 - 1] = 'O';
  1211. X            lasttok.A[4 - 1] = 'F';
  1212. X            lasttok.A[5 - 1] = '*';
  1213. X            (*G181_lastchr) = 6;
  1214. X            W46->st = seof;
  1215. X        } else
  1216. X            switch (c) {
  1217. X              case '|':  case '`':  case '~':  case '}':
  1218. X              case 92:  case 95:  case 63:
  1219. X                error(ebadchar);
  1220. X                break ;
  1221. X              case 'a':  case 'b':  case 'c':  case 'd':
  1222. X              case 'e':  case 'f':  case 'g':  case 'h':
  1223. X              case 'i':  case 'j':  case 'k':  case 'l':
  1224. X              case 'm':  case 'n':  case 'o':  case 'p':
  1225. X              case 'q':  case 'r':  case 's':  case 't':
  1226. X              case 'u':  case 'v':  case 'w':  case 'x':
  1227. X              case 'y':  case 'z':  case 'A':  case 'B':
  1228. X              case 'C':  case 'D':  case 'E':  case 'F':
  1229. X              case 'G':  case 'H':  case 'I':  case 'J':
  1230. X              case 'K':  case 'L':  case 'M':  case 'N':
  1231. X              case 'O':  case 'P':  case 'Q':  case 'R':
  1232. X              case 'S':  case 'T':  case 'U':  case 'V':
  1233. X              case 'W':  case 'X':  case 'Y':  case 'Z':
  1234. X                wb.A[1 - 1] = lowercase(c);
  1235. X                wl = 2;
  1236. X                while ((wl < maxtoknlen) && idchar(peekchar())) {
  1237. X                    wb.A[wl - 1] = lowercase(nextchar());
  1238. X                    wl = wl + 1;
  1239. X                }
  1240. X                if (wl >= maxtoknlen) {
  1241. X                    lasttok.A[(*G181_lastchr) - 1] = null;
  1242. X                    error(elongtokn);
  1243. X                }
  1244. X                wb.A[wl - 1] = null;
  1245. X                W46->st = keywordcheck(&wb, wl - 1);
  1246. X                if (W46->st == sid)
  1247. X                    W46->U.V1.vid = saveid(&wb);
  1248. X                break ;
  1249. X              case '0':  case '1':  case '2':  case '3':
  1250. X              case '4':  case '5':  case '6':  case '7':
  1251. X              case '8':  case '9':
  1252. X                wb.A[1 - 1] = c;
  1253. X                wl = 2;
  1254. X                n = numval(c);
  1255. X                while (numchar(peekchar())) {
  1256. X                    c = nextchar();
  1257. X                    n = n * 10 + numval(c);
  1258. X                    wb.A[wl - 1] = c;
  1259. X                    wl = wl + 1;
  1260. X                }
  1261. X                W46->st = sinteger;
  1262. X                W46->U.V3.vint = n;
  1263. X                if (realok) {
  1264. X                    if (peekchar() == '.') {
  1265. X                        W46->st = sreal;
  1266. X                        wb.A[wl - 1] = nextchar();
  1267. X                        wl = wl + 1;
  1268. X                        while (numchar(peekchar())) {
  1269. X                            wb.A[wl - 1] = nextchar();
  1270. X                            wl = wl + 1;
  1271. X                        }
  1272. X                    }
  1273. X                    c = peekchar();
  1274. X                    if ((c == 'e') || (c == 'E')) {
  1275. X                        W46->st = sreal;
  1276. X                        c = nextchar();
  1277. X                        wb.A[wl - 1] = xpnent;
  1278. X                        wl = wl + 1;
  1279. X                        c = peekchar();
  1280. X                        if ((c == '-') || (c == '+')) {
  1281. X                            wb.A[wl - 1] = nextchar();
  1282. X                            wl = wl + 1;
  1283. X                        }
  1284. X                        while (numchar(peekchar())) {
  1285. X                            wb.A[wl - 1] = nextchar();
  1286. X                            wl = wl + 1;
  1287. X                        }
  1288. X                    }
  1289. X                    if (W46->st == sreal) {
  1290. X                        wb.A[wl - 1] = null;
  1291. X                        W46->U.V4.vflt = savestr(&wb);
  1292. X                    }
  1293. X                }
  1294. X                break ;
  1295. X              case '(':
  1296. X                if (peekchar() == '.') {
  1297. X                    c = nextchar();
  1298. X                    W46->st = slbrack;
  1299. X                } else
  1300. X                    W46->st = slpar;
  1301. X                break ;
  1302. X              case ')':
  1303. X                W46->st = srpar;
  1304. X                break ;
  1305. X              case '[':
  1306. X                W46->st = slbrack;
  1307. X                break ;
  1308. X              case ']':
  1309. X                W46->st = srbrack;
  1310. X                break ;
  1311. X              case '.':
  1312. X                if (peekchar() == '.') {
  1313. X                    c = nextchar();
  1314. X                    W46->st = sdotdot;
  1315. X                } else
  1316. X                    if (peekchar() == ')') {
  1317. X                        c = nextchar();
  1318. X                        W46->st = srbrack;
  1319. X                    } else
  1320. X                        W46->st = sdot;
  1321. X                break ;
  1322. X              case ';':
  1323. X                W46->st = ssemic;
  1324. X                break ;
  1325. X              case ':':
  1326. X                if (peekchar() == '=') {
  1327. X                    c = nextchar();
  1328. X                    W46->st = sassign;
  1329. X                } else
  1330. X                    W46->st = scolon;
  1331. X                break ;
  1332. X              case ',':
  1333. X                W46->st = scomma;
  1334. X                break ;
  1335. X              case '@':  case '^':
  1336. X                W46->st = sarrow;
  1337. X                break ;
  1338. X              case '=':
  1339. X                W46->st = seq;
  1340. X                break ;
  1341. X              case '<':
  1342. X                if (peekchar() == '=') {
  1343. X                    c = nextchar();
  1344. X                    W46->st = sle;
  1345. X                } else
  1346. X                    if (peekchar() == '>') {
  1347. X                        c = nextchar();
  1348. X                        W46->st = sne;
  1349. X                    } else
  1350. X                        W46->st = slt;
  1351. X                break ;
  1352. X              case '>':
  1353. X                if (peekchar() == '=') {
  1354. X                    c = nextchar();
  1355. X                    W46->st = sge;
  1356. X                } else
  1357. X                    W46->st = sgt;
  1358. X                break ;
  1359. X              case '+':
  1360. X                W46->st = splus;
  1361. X                break ;
  1362. X              case '-':
  1363. X                W46->st = sminus;
  1364. X                break ;
  1365. X              case '*':
  1366. X                W46->st = smul;
  1367. X                break ;
  1368. X              case '/':
  1369. X                W46->st = squot;
  1370. X                break ;
  1371. X              case 39:
  1372. X                wl = 0;
  1373. X                ready = false;
  1374. X                do {
  1375. X                    if (Eoln(input)) {
  1376. X                        lasttok.A[(*G181_lastchr) - 1] = null;
  1377. X                        error(ebadstring);
  1378. X                    }
  1379. X                    c = nextchar();
  1380. X                    if (c == quote)
  1381. X                        if (peekchar() == quote)
  1382. X                            c = nextchar();
  1383. X                        else
  1384. X                            ready = true;
  1385. X                    if (c == null) {
  1386. X                        if (Eof(input))
  1387. X                            error(eeofstr);
  1388. X                        lasttok.A[(*G181_lastchr) - 1] = null;
  1389. X                        error(enulchr);
  1390. X                    }
  1391. X                    if (!ready) {
  1392. X                        wl = wl + 1;
  1393. X                        if (wl >= maxtoknlen) {
  1394. X                            lasttok.A[(*G181_lastchr) - 1] = null;
  1395. X                            error(elongstring);
  1396. X                        }
  1397. X                        wb.A[wl - 1] = c;
  1398. X                    }
  1399. X                } while (!(ready));
  1400. X                if (wl == 1) {
  1401. X                    W46->st = schar;
  1402. X                    W46->U.V2.vchr = wb.A[1 - 1];
  1403. X                } else {
  1404. X                    wl = wl + 1;
  1405. X                    if (wl >= maxtoknlen) {
  1406. X                        lasttok.A[(*G181_lastchr) - 1] = null;
  1407. X                        error(elongstring);
  1408. X                    }
  1409. X                    wb.A[wl - 1] = null;
  1410. X                    W46->st = sstring;
  1411. X                    W46->U.V5.vstr = savestr(&wb);
  1412. X                }
  1413. X                break ;
  1414. X              default:
  1415. X                Caseerror(Line);
  1416. X            }
  1417. X    }
  1418. X    if ((*G181_lastchr) == 0)
  1419. X        (*G181_lastchr) = 1;
  1420. X    lasttok.A[(*G181_lastchr) - 1] = null;
  1421. X}
  1422. X
  1423. X void
  1424. Xnextsymbol(ss)
  1425. X    symset    ss;
  1426. X{
  1427. X    unsigned char    lastchr;
  1428. X    unsigned char    *F182;
  1429. X
  1430. X    F182 = G181_lastchr;
  1431. X    G181_lastchr = &lastchr;
  1432. X    nexttoken((boolean)(Member((unsigned)(sreal), ss.S)));
  1433. X    checksymbol(ss);
  1434. X    G181_lastchr = F182;
  1435. X}
  1436. X
  1437. X treeptr
  1438. Xtypeof(tp)
  1439. X    treeptr    tp;
  1440. X{
  1441. X    register treeptr    R92;
  1442. X    treeptr    tf, tq;
  1443. X
  1444. X    tq = tp;
  1445. X    tf = tq->ttype;
  1446. X    while (tf == (struct S61 *)NIL) {
  1447. X        switch (tq->tt) {
  1448. X          case nchar:
  1449. X            tf = typnods.A[(int)(tchar)];
  1450. X            break ;
  1451. X          case ninteger:
  1452. X            tf = typnods.A[(int)(tinteger)];
  1453. X            break ;
  1454. X          case nreal:
  1455. X            tf = typnods.A[(int)(treal)];
  1456. X            break ;
  1457. X          case nstring:
  1458. X            tf = typnods.A[(int)(tstring)];
  1459. X            break ;
  1460. X          case nnil:
  1461. X            tf = typnods.A[(int)(tnil)];
  1462. X            break ;
  1463. X          case nid:
  1464. X            tq = idup(tq);
  1465. X            if (tq == (struct S61 *)NIL)
  1466. X                fatal(etree);
  1467. X            break ;
  1468. X          case ntype:  case nvar:  case nconst:  case nfield:
  1469. X          case nvalpar:  case nvarpar:
  1470. X            tq = tq->U.V14.tbind;
  1471. X            break ;
  1472. X          case npredef:  case nptr:  case nscalar:  case nrecord:
  1473. X          case nconfarr:  case narray:  case nfileof:  case nsetof:
  1474. X            tf = tq;
  1475. X            break ;
  1476. X          case nsubrange:
  1477. X            if (tq->tup->tt == nconfarr)
  1478. X                tf = tq->tup->U.V22.tindtyp;
  1479. X            else
  1480. X                tf = tq;
  1481. X            break ;
  1482. X          case ncall:
  1483. X            tf = typeof(tq->U.V30.tcall);
  1484. X            if (tf == typnods.A[(int)(tpoly)])
  1485. X                tf = typeof(tq->U.V30.taparm);
  1486. X            break ;
  1487. X          case nfunc:
  1488. X            tq = tq->U.V13.tfuntyp;
  1489. X            break ;
  1490. X          case nparfunc:
  1491. X            tq = tq->U.V15.tpartyp;
  1492. X            break ;
  1493. X          case nproc:  case nparproc:
  1494. X            tf = typnods.A[(int)(tnone)];
  1495. X            break ;
  1496. X          case nvariant:  case nlabel:  case npgm:  case nempty:
  1497. X          case nbegin:  case nlabstmt:  case nassign:  case npush:
  1498. X          case npop:  case nif:  case nwhile:  case nrepeat:
  1499. X          case nfor:  case ncase:  case nchoise:  case ngoto:
  1500. X          case nwith:  case nwithvar:
  1501. X            fatal(etree);
  1502. X            break ;
  1503. X          case nformat:  case nrange:
  1504. X            tq = tq->U.V41.texpl;
  1505. X            break ;
  1506. X          case nplus:  case nminus:  case nmul:
  1507. X            tf = typeof(tq->U.V41.texpl);
  1508. X            if (tf == typnods.A[(int)(tinteger)])
  1509. X                tf = typeof(tq->U.V41.texpr);
  1510. X            else
  1511. X                if (tf->tt == nsetof)
  1512. X                    tf = typnods.A[(int)(tset)];
  1513. X            break ;
  1514. X          case numinus:  case nuplus:
  1515. X            tq = tq->U.V42.texps;
  1516. X            break ;
  1517. X          case nmod:  case ndiv:
  1518. X            tf = typnods.A[(int)(tinteger)];
  1519. X            break ;
  1520. X          case nquot:
  1521. X            tf = typnods.A[(int)(treal)];
  1522. X            break ;
  1523. X          case neq:  case nne:  case nlt:  case nle:
  1524. X          case ngt:  case nge:  case nin:  case nor:
  1525. X          case nand:  case nnot:
  1526. X            tf = typnods.A[(int)(tboolean)];
  1527. X            break ;
  1528. X          case nset:
  1529. END_OF_FILE
  1530. if test 33774 -ne `wc -c <'ptc.c.1'`; then
  1531.     echo shar: \"'ptc.c.1'\" unpacked with wrong size!
  1532. fi
  1533. # end of 'ptc.c.1'
  1534. fi
  1535. echo shar: End of archive 3 \(of 12\).
  1536. cp /dev/null ark3isdone
  1537. MISSING=""
  1538. for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
  1539.     if test ! -f ark${I}isdone ; then
  1540.     MISSING="${MISSING} ${I}"
  1541.     fi
  1542. done
  1543. if test "${MISSING}" = "" ; then
  1544.     echo You have unpacked all 12 archives.
  1545.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1546. else
  1547.     echo You still need to unpack the following archives:
  1548.     echo "        " ${MISSING}
  1549. fi
  1550. ##  End of shell archive.
  1551. exit 0
  1552. -- 
  1553.  
  1554. Rich $alz            "Anger is an energy"
  1555. Cronus Project, BBN Labs    rsalz@bbn.com
  1556. Moderator, comp.sources.unix    sources@uunet.uu.net
  1557.